<template>
  <div class="home">
    <el-container>
      <el-header>
        <el-row :gutter="20">
          <el-col :span="4">
            <div class="grid-content ep-bg-purple">
              <img src="../assets/logo.png" alt="" class="logo" />
            </div>
          </el-col>
          <el-col :span="16">
            <div class="grid-content ep-bg-purple">
              <h2>后台管理系统</h2>
            </div>
          </el-col>
          <el-col :span="4">
            <div class="grid-content ep-bg-purple">
              <span class="quit-login">
                <el-button @click="quitLogin">退出登录</el-button>
              </span>
            </div>
          </el-col>
        </el-row>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu
            active-text-color="#ffd04b"
            background-color="#545c64"
            class="el-menu-vertical-demo"
            :default-active="active"
            text-color="#fff"
            router
          >
            <!-- router开启路由模式，通过el-menu-item的index来跳转 -->
            <el-menu-item
              :index="item.path"
              v-for="item in list"
              :key="item.path"
            >
              <el-icon></el-icon>
              <span>{{ item.meta.title }}</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script lang="ts" setup>
import { computed } from "vue";
import { useRoute, useRouter } from "vue-router";

const router = useRouter();
const route = useRoute();
const active = computed(() => {
  return route.path;
});
const list = computed(()=>{
  return router.getRoutes().filter((v) => v.meta.isShow)
});
console.log(list)
//
console.log(router.getRoutes());

// console.log(list)
const quitLogin = () => {
  localStorage.removeItem("token");
  router.push("/login");
};
// console.log(list);
</script>
<style lang="scss">
.el-header {
  height: 80px;
  background-color: #666;
  .logo {
    height: 80px;
  }

  h2,
  .quit-login {
    text-align: center;
    height: 80px;
    line-height: 80px;
    color: #fff;
  }
}

.el-aside {
  .el-menu {
    height: calc(100vh - 80px);
  }
}
</style>
